﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Data;
using System.Linq;
using System.Text;
using WMSABL.SY;

namespace ElectronicWMSA.SY.ListFrm
{
    public partial class OrganizationListFrm : Form
    {
        TOrganization_BLL bll_TOrganization = new TOrganization_BLL();
        public int Organization_id = 0;
        public OrganizationListFrm()
        {
            InitializeComponent();
        }

        private void OrganizationListFrm_Load(object sender, EventArgs e)
        {
            DBindOrganization();
        }

        public void DBindOrganization()
        {
            this.treeViewList.Nodes.Clear();
            DataSet ds = new DataSet();
            ds = bll_TOrganization.GetList_TOrganization();
            DataTable dt = new DataTable();
            dt = ds.Tables[0];
            DataView dv = new DataView(dt);
            dv.RowFilter = "Parent_id=0";
            foreach (DataRowView drv in dv)
            {
                TreeNode node = new TreeNode();
                node.Text = drv["Organization_name"].ToString();
                node.Name = drv["Organization_id"].ToString();
                treeViewList.Nodes.Add(node);
                this.AddNodes(dt, node);
            }
            this.treeViewList.ExpandAll();
            this.treeViewList.SelectedNode = treeViewList.TopNode; //最顶端节点选中
        }

        /// <summary>
        /// AddNodes
        /// </summary>
        /// <param name="dt">dt</param>
        /// <param name="node">node</param>
        public void AddNodes(DataTable dt, TreeNode node)
        {
            DataView dv = new DataView(dt);
            dv.RowFilter = "Parent_id='" + node.Name + "'";
            foreach (DataRowView row in dv)
            {
                TreeNode replyNode = new TreeNode();
                replyNode.Text = row["Organization_name"].ToString();
                replyNode.Name = row["Organization_id"].ToString();
                node.Nodes.Add(replyNode);
                this.AddNodes(dt, replyNode);
            }
        }

        private void treeViewDomain_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            this.Organization_id = Convert.ToInt32(e.Node.Name);
            this.Close();
        }
    }
}
